<?php
/**
 * CreateTime: 2024/1/22 11:29
 * User:LinQ
 */

namespace App\Models\Goods;

use App\Models\BasicModel;

class GoodsModel extends BasicModel
{
    protected $table = 'goods';

    protected $fillable = [
        'goods_id',
        'com_id',
        'goods_show_image_id',
        'goods_image_ids',
        'goods_name',
        'goods_simple_name',
        'goods_brand',
        'belonging_works',
        'shipping_location_info',
        'sales_method',
        'goods_uuid',
        'goods_status',
        'group_id',
        'goods_type_id',
        'goods_describe',
        'goods_stock',
        'stock_status',
        'enable_status',
        'status',
        'created_at',
        'updated_at'
    ];

    protected $hidden = [
        'com_id',
        'status',
        'created_at',
        'updated_at'
    ];

    protected $casts = [
        'goods_id' => 'integer',
        'goods_show_image_id' => 'integer',
        'goods_image_ids' => 'string',
        'goods_name' => 'string',
        'goods_simple_name' => 'string',
        'goods_brand' => 'string',
        'belonging_works' => 'string',
        'shipping_location_info' => 'string',
        'sales_method' => 'string',
        'goods_uuid' => 'string',
        'goods_status'=> 'integer',
        'group_id'=> 'integer',
        'goods_type_id'=> 'integer',
        'goods_describe' => 'string',
        'goods_stock'=> 'integer',
        'stock_status'=> 'integer',
        'enable_status'=> 'integer',
        'status'=> 'integer',
        'created_at' => 'string',
        'updated_at' => 'string'
    ];

    public function getGoodsTypeStrAttribute($value): string
    {
        $value = (int)$value;
        return GoodsTypeModel::select(['goods_type_name'])->find($value)->goods_type_name ?? "-";
    }
}
